/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

/**
 * <p>Project: jse2302 - Stream05
 * <p>Powered by webrx On 2023-06-29 11:38:46
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Stream05 {
    public static void main(String[] args) {
        Stream<Integer> is = Stream.of(1, 2, 3, 4);
        Optional<Integer> reduce = is.reduce((a, b) -> a + b);
        System.out.println(reduce.get());

        System.out.println(1*2*3*4*5*6);
        System.out.println(IntStream.rangeClosed(1, 6).reduce((a, b) -> a * b).getAsInt());

        //IntStream
        //LongStream
        //DoubleStream
        //Stream<Integer>
        //Stream<String>

        Stream<String> ss = Stream.of("a","b","c","a","a","c","d");
        //流变字符串
        //String s1 = ss.collect(Collectors.joining());
        //String s1 = ss.collect(Collectors.joining(","));
        //System.out.println(s1);

        //List<String> list = ss.toList();
        //List<String> list = ss.collect(Collectors.toList());
        Set<String> list = ss.collect(Collectors.toSet());
        System.out.println(list);
        System.out.println(list);
        System.out.println(list);
        System.out.println(list);

    }
}
